package com.ftg.shopping.userGroupPrivilege.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserGroupPrivilegeMapper  extends BaseMapper {

    @Select("SELECT a.userId,a.userName,b.personName,b.position,c.dname FROM \n" +
            "sp_userinfo a LEFT JOIN sp_personinfo b ON a.userId=b.personId  LEFT JOIN sp_deptinfo\n" +
            "c ON c.deptno=b.deptNo"+
            " limit #{page2} ,#{limit}"
           )
    List<Map<String,Object>> selectall(int page2, int limit);

   @Select("SELECT a.userId,a.userName,b.personName,b.position,c.dname FROM \n" +
           "sp_userinfo a LEFT JOIN sp_personinfo b ON a.userId=b.personId  LEFT JOIN sp_deptinfo\n" +
           "c ON c.deptno=b.deptNo")
   List<Map<String,Object>> selectall2();

   @Select("SELECT a.userId,a.userName,b.personName,b.position,c.dname FROM sp_userinfo a LEFT JOIN sp_personinfo b ON a.userId=b.personId  LEFT JOIN sp_deptinfo c ON c.deptno=b.deptNo "+
           " where a.userName like concat(#{userName},'%')"+
           " limit #{page2} ,#{limit}")
   List<Map<String,Object>> selectall3(int page2, int limit, String userName);

    @Select("SELECT a.userId,a.userName,b.personName,b.position,c.dname FROM sp_userinfo a LEFT JOIN sp_personinfo b ON a.userId=b.personId  LEFT JOIN sp_deptinfo c ON c.deptno=b.deptNo "+
            " where a.userName like concat(#{userName},'%')")
    List<Map<String,Object>> selectall4(String userName);


    @Select("SELECT a.*,case when userid IS NOT NULL then true ELSE false END 'LAY_CHECKED' FROM sp_roleinfo a LEFT JOIN (SELECT * from sp_userprivilege_mid WHERE userid = #{userid}) b ON a.roleid = b.roleid")
    List<Map<String, Object>> role2(String userid);

    @Insert("Insert into sp_userprivilege_mid(userid,roleid) values(#{userid},#{cla})")
    int insertmore(int userid, String cla);
}
